package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.Power;

@Repository
public interface PowerDao extends JpaRepository<Power, Integer>, JpaSpecificationExecutor<Power> {

	@Query("from Power where code = ?1")
	List<Power> find(String name);

	@Query("from Power where code like ?1")
	List<Power> findLike(String name);

	@Query(value = "select * from Power limit ?, ?", nativeQuery = true)
	List<Power> findPage(Integer offset, Integer size);

	@Query(value = "select * from Power where code = ? limit ?, ?", nativeQuery = true)
	List<Power> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from Power where code like ? limit ?, ?", nativeQuery = true)
	List<Power> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from Power where code = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from Power where code like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from Power order by id asc")
	List<Power> findAllAsc();
}

